// JavaScript Document

var homevar = document.getElementById('homelocationsaver');
var autocompletehome = new google.maps.places.Autocomplete(homevar);

function datapasser(){
	var from = $('input[name=from]').val();
	var to = $('input[name=to]').val();

	localStorage.setItem('from', from);
	localStorage.setItem('to', to);	
}

function initialchecker()
{
	document.getElementById("homelocationsaver").value= "";
	document.getElementById("worklocationsaver").value= "";
	if (localStorage.getItem('homeloc') != null)
	{
		  $('#save').removeClass('ui-btn-up-c ui-btn-hover-c ui-btn-down-c').addClass('ui-btn-up-e ui-btn-hover-e ui-btn-down-e').attr('data-theme', 'c');
		  var gethomeloc = localStorage.getItem('homeloc');
		  $('#homelocationsaver').attr('placeholder',gethomeloc);
	}
	if (localStorage.getItem('workloc') != null)
	{
		$('#save2').removeClass('ui-btn-up-c ui-btn-hover-c ui-btn-down-c').addClass('ui-btn-up-e ui-btn-hover-e ui-btn-down-e').attr('data-theme', 'c');
		var getworkloc = localStorage.getItem('workloc');
		$('#worklocationsaver').attr('placeholder',getworkloc);
	}
}
		
function sethomeloc() //gets called when the user presses 'SAVE' from the my profile page
{
  var homeloc = $('input[name=homelocationsaver]').val();
  localStorage.setItem('homeloc', homeloc);
  $('#save').removeClass('ui-btn-up-c ui-btn-hover-c ui-btn-down-c').addClass('ui-btn-up-e ui-btn-hover-e ui-btn-down-e').attr('data-theme', 'c');  
}
		
function gethomeloc(val)
{
  var gethomeloc = localStorage.getItem('homeloc');
  console.log(gethomeloc);
  if (val == 1)
  {
	  document.getElementById('from').value = gethomeloc;
	  /*var buttonid = document.getElementById('usehomein-from');
	  var current_theme = buttonid.getAttribute('data-theme'); 
	  console.log(current_theme);*/
	  $('#usehomein-from').removeClass('ui-btn-up-c ui-btn-hover-c ui-btn-down-c').addClass('ui-btn-up-b ui-btn-hover-b ui-btn-down-b').attr('data-theme', 'b');
	  $('#useworkin-from').removeClass('ui-btn-up-b ui-btn-hover-b ui-btn-down-b').addClass('ui-btn-up-c ui-btn-hover-c ui-btn-down-c').attr('data-theme', 'c');
	  $('#usegpsin-from').removeClass('ui-btn-up-b ui-btn-hover-b ui-btn-down-b').addClass('ui-btn-up-c ui-btn-hover-c ui-btn-down-c').attr('data-theme', 'c');	  
	  $('#tourist-from').removeClass('ui-btn-up-f ui-btn-hover-f ui-btn-down-f').addClass('ui-btn-up-c ui-btn-hover-c ui-btn-down-c').attr('data-theme', 'c');	  
  }
  if (val == 2)
  {
	  document.getElementById('to').value = gethomeloc;
	  $('#usehomein-to').removeClass('ui-btn-up-c ui-btn-hover-c ui-btn-down-c').addClass('ui-btn-up-b ui-btn-hover-b ui-btn-down-b').attr('data-theme', 'b');
	  $('#useworkin-to').removeClass('ui-btn-up-b ui-btn-hover-b ui-btn-down-b').addClass('ui-btn-up-c ui-btn-hover-c ui-btn-down-c').attr('data-theme', 'c');
	  $('#usegpsin-to').removeClass('ui-btn-up-b ui-btn-hover-b ui-btn-down-b').addClass('ui-btn-up-c ui-btn-hover-c ui-btn-down-c').attr('data-theme', 'c');	  
	  $('#tourist-to').removeClass('ui-btn-up-f ui-btn-hover-f ui-btn-down-f').addClass('ui-btn-up-c ui-btn-hover-c ui-btn-down-c').attr('data-theme', 'c');	  
	  
	  
  }

}

function deletehomeloc()
{
  localStorage.removeItem('homeloc');
  $('#homelocationsaver').attr('placeholder','Location name');
  $("a[name='usehomein-from']").addClass('ui-disabled');
  $("a[name='usehomein-to']").addClass('ui-disabled');
  $('#save').removeClass('ui-btn-up-e ui-btn-hover-e ui-btn-down-e').addClass('ui-btn-up-c ui-btn-hover-c ui-btn-down-c');  
 
   document.getElementById('homelocationsaver').value = null;

}

function enablehomebutton()
{
    $("a[name='usehomein-from']").removeClass('ui-disabled');
	$("a[name='usehomein-to']").removeClass('ui-disabled');
}

//----------------------------------------------------------------------------------------------------------------------------
var workvar = document.getElementById('worklocationsaver');
var autocompletework = new google.maps.places.Autocomplete(workvar);
				
function setworkloc() //gets called when the user presses 'SAVE' from the my profile page
{
  var workloc = $('input[name=worklocationsaver]').val();
  localStorage.setItem('workloc', workloc);	
  $('#save2').removeClass('ui-btn-up-c ui-btn-hover-c ui-btn-down-c').addClass('ui-btn-up-e ui-btn-hover-e ui-btn-down-e').attr('data-theme', 'c');  
}
		
function getworkloc(val)
{
  var getworkloc = localStorage.getItem('workloc');
  console.log(getworkloc);
  if (val == 1)
  {
	  document.getElementById('from').value = getworkloc;
	  $('#useworkin-from').removeClass('ui-btn-up-c ui-btn-hover-c ui-btn-down-c').addClass('ui-btn-up-b ui-btn-hover-b ui-btn-down-b').attr('data-theme', 'b');
	  $('#usehomein-from').removeClass('ui-btn-up-b ui-btn-hover-b ui-btn-down-b').addClass('ui-btn-up-c ui-btn-hover-c ui-btn-down-c').attr('data-theme', 'c');
	  $('#usegpsin-from').removeClass('ui-btn-up-b ui-btn-hover-b ui-btn-down-b').addClass('ui-btn-up-c ui-btn-hover-c ui-btn-down-c').attr('data-theme', 'c');	  	  
	  $('#tourist-from').removeClass('ui-btn-up-f ui-btn-hover-f ui-btn-down-f').addClass('ui-btn-up-c ui-btn-hover-c ui-btn-down-c').attr('data-theme', 'c');	  
  }
  if (val == 2)
  {
	  document.getElementById('to').value = getworkloc;
	  $('#useworkin-to').removeClass('ui-btn-up-c ui-btn-hover-c ui-btn-down-c').addClass('ui-btn-up-b ui-btn-hover-b ui-btn-down-b').attr('data-theme', 'b');
	  $('#usehomein-to').removeClass('ui-btn-up-b ui-btn-hover-b ui-btn-down-b').addClass('ui-btn-up-c ui-btn-hover-c ui-btn-down-c').attr('data-theme', 'c');
	  $('#usegpsin-to').removeClass('ui-btn-up-b ui-btn-hover-b ui-btn-down-b').addClass('ui-btn-up-c ui-btn-hover-c ui-btn-down-c').attr('data-theme', 'c');	  
	  $('#tourist-to').removeClass('ui-btn-up-f ui-btn-hover-f ui-btn-down-f').addClass('ui-btn-up-c ui-btn-hover-c ui-btn-down-c').attr('data-theme', 'c');	  	  
  }
}	

function deleteworkloc()
{
  localStorage.removeItem('workloc');
  $('#worklocationsaver').attr('placeholder','Location name');
  $("a[name='useworkin-from']").addClass('ui-disabled');
  $("a[name='useworkin-to']").addClass('ui-disabled');
  $('#save2').removeClass('ui-btn-up-e ui-btn-hover-e ui-btn-down-e').addClass('ui-btn-up-c ui-btn-hover-c ui-btn-down-c');  
  
  document.getElementById('worklocationsaver').value = null;
}

function enableworkbutton()
{
    $("a[name='useworkin-from']").removeClass('ui-disabled');
	$("a[name='useworkin-to']").removeClass('ui-disabled');
}
